package com.trkj.controllers;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.trkj.pojos.HospWorkOutNotice;
import com.trkj.pojos.LiveinrecordTable;
import com.trkj.pojos.LiveoutTable;
import com.trkj.pojos.LivetypeTable;
import com.trkj.pojos.VisitTable;
import com.trkj.service.BigOfficeService;
import com.trkj.service.CardService;
import com.trkj.service.HospWorkInNoticeService;
import com.trkj.service.LiveInService;
import com.trkj.service.LiveOutService;
import com.trkj.service.LiveTypeService;
import com.trkj.service.TallyService;
import com.trkj.vo.BigOfficeTypeVo;
import com.trkj.vo.CardVo;
import com.trkj.vo.SmallOfficeTypeVo;
@Controller
public final class HospitalLiveController {
	@Autowired
	private LiveInService lv;
	@Autowired
	private CardService cds;
	@Autowired
	private HospWorkInNoticeService hws;
	@Autowired
	private LiveTypeService lts;
	@Autowired
	private BigOfficeService bfs;
	@Autowired
	private TallyService tallyService;
	@Autowired
	private LiveOutService liveOutService;
	
	/**
	 * 新增入院登记
	 */
	@RequestMapping("/to_AddLiveInRecode")
	@ResponseBody
	public boolean addLiveInPetain(LiveinrecordTable lt,BigDecimal despoit,
			String DoctorID,String MedicalId,Long BedId){
		return lv.addLiveInPatient(lt, despoit, DoctorID, MedicalId, BedId);
	}
	/**
	 * 跳转liveADD页面
	 * @return
	 */
	@RequestMapping("/to_new_hspt_live_in")
	public String to_new_hspt_live_in(){
		return "hspt_live_In_add";
	}
	/**
	 *  并生成住院号
	 * @return
	 */
	@RequestMapping("/to_new_hspt_createLiveID")
	@ResponseBody
	public String createLiveID(){
		return lv.createLiveID();
		
	}
	/**
	 * 跳转hspt_visiter_add页面 
	 * @return
	 */
	@RequestMapping("/to_hspt_visiter_add")
	public String to_hspt_visiter_add(){
		return "hspt_visiter_add";
	}
	/**
	 * 生成探望号
	 * @return
	 */
	@RequestMapping("/to_initVisitorID")
	@ResponseBody
	public Map<String,Object> initVisitorID(){
		return lv.createVisitID();
	}
	/**
	 * 添加探望记录
	 * @param liveInID
	 * @param visitTable
	 */
	@RequestMapping("/to_visitor_add")
	public void visitorAdd(String liveInID,VisitTable visitTable){
		lv.addvisitor(liveInID, visitTable);
	}
	/**
	 * 分页查询探望记录
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/to_fuzzyqueryvisitor")
	@ResponseBody
	public Map<String,Object> fuzzyqueryvisitor(String starDate,String endDate,int page,int rows){
		return lv.queryviasitor(starDate, endDate, page, rows);
	}
	/**
	 * 根据住院号查询探望
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_queryvisitorByLiveID")
	@ResponseBody
	public List<VisitTable> queryvisitorByLiveID(String liveID){
		return lv.queryvisitorByLiveID(liveID);
	}
	
	/**
	 * 根据住院号查病人信息
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_hspt_live_patientInfo")
	public ModelAndView queryLiveByLiveID(String liveID ){
		ModelAndView mv = new  ModelAndView("hspt_live_patientInfo");
		LiveinrecordTable live = lv.queryLiveByLiveID(liveID);
		mv.addObject("liveRecord",live);
		return mv;
	}
	/**
	 * 动态查询主治医生
	 * @param page
	 * @param rows
	 * @param officeName
	 * @param dutyName
	 * @param DoctorName
	 * @return
	 */
	@RequestMapping("/to_hspt_live_fuzzyfineDoctor")
	@ResponseBody
	public Map<String,Object> fuzzyQueryDoctor(int page,int rows,
			String officeName,String dutyName,String DoctorName){
		return lv.fuzzyQueryDoctor(page, rows, officeName, dutyName, DoctorName);
		
	}
	/**
	 * 动态查询住院病人
	 * @param page
	 * @param rows
	 * @param liveoffice4
	 * @param afterLivedate
	 * @param beforeLivedate
	 * @param patientsex
	 * @return
	 */
	@RequestMapping("/to_dynamicQueryLiveIn")
	@ResponseBody
	public Map<String,Object> dynamicQueryLiveIn(int page ,int rows,String liveoffice4,
							String afterLivedate, String beforeLivedate,String patientsex){
		Map<String,Object> map = new HashMap<>();
		map.put("liveoffice4", liveoffice4);
		map.put("afterLivedate", afterLivedate);
		map.put("beforeLivedate", beforeLivedate);
		map.put("patientsex", patientsex);
		map.put("livestatus", "在院");
		return lv.dynamicQueryLiveIn(map,page,rows);
	}
	/**
	 * 根据姓名模糊查询住院病人
	 * @param page
	 * @param rows
	 * @param likename
	 * @return
	 */
	@RequestMapping("/to_fuzzyQueryLiveIn")
	@ResponseBody
	public Map<String,Object> fuzzyQueryLiveIn(int page ,int rows,String likename){
		return lv.fuzzyQueryLiveInByname(likename, page, rows);
	}
	/**
	 * 模糊查询住院通知
	 * @param likePname
	 * @return
	 */
	@RequestMapping("/to_queryLikeNotic")
	@ResponseBody
	public List<Map<String,Object>> queryNotic(String likePname){
		return hws.likequeryNoticByNmae(likePname);
	}
	/**
	 * 分页查询账单BY liveID
	 * @param page
	 * @param rows
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_queryTallyByLiveID")
	@ResponseBody
	public Map<String,Object> queryTallyByLiveID(int page,int rows,String liveID){
		return tallyService.queryTallyByLiveID(page, rows, liveID);
	}
	/**
	 * 分页查询缴费单BY liveID
	 * @param page
	 * @param rows
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_queryPayByLiveID")
	@ResponseBody
	public Map<String,Object> queryPayByLiveID(int page,int rows,String liveID){
		return tallyService.queryPayByLiveID(page, rows, liveID);
	}
	/**
	 * 模糊查询诊疗卡by name
	 * @param likename
	 * @return
	 */
	@RequestMapping("/to_Medical_queryLikeName")
	@ResponseBody
	public List<CardVo> queryMedicalByLikeName(String likename){
		return cds.likeQueryCidByName(likename);
	}
	/**
	 * 模糊查询诊疗卡by id
	 * @param likeID
	 * @return
	 */
	@RequestMapping("/to_Medical_queryLikeID")
	@ResponseBody
	public List<CardVo> queryMedicalByLikeID(String likeID){
		return cds.likeQueryCidByID(likeID);
		
	}
	/**
	 * 跳转医疗卡查询界面
	 * @return
	 */
	@RequestMapping("/to_Medical_queryWindow")
	public String to_Medical_queryWindow(){
		return "hspt_medicalCard_quary";
		
	}
	/**
	 * 查询所有住院类型
	 * @return
	 */
	@RequestMapping("/to_AllLiveType")
	@ResponseBody
	public Iterable<LivetypeTable> allLiveType(){
		return lts.queryAllType() ;
	}
	/**
	 * 查询所有的科室  树形结构
	 * @return
	 */
	@RequestMapping("/to_QueryAllOffice")
	@ResponseBody
	public List<BigOfficeTypeVo> queryAllOffice(){
		return bfs.findOfficeTree();
	}
	/**
	 * 查询所有住院科室 
	 * @return
	 */
	@RequestMapping("/to_QueryLiveOffice")
	@ResponseBody
	public List<SmallOfficeTypeVo> queryLiveOffice(){
		return bfs.queryLiveOffice();
	}
	/**
	 * 跳转出院通知界面
	 * @return
	 */
	@RequestMapping("/to_new_hspt_live_out")
	public String to_new_hspt_live_out( ){
		return "hspt_live_out_add";
		
	}
	/**
	 * 跳转费用核算界面
	 * @return
	 */
	@RequestMapping("/to_hspt_live_fees_account")
	public String to_hspt_live_fees_account( ){
		return "hspt_live_fees_account";
		
	}
	
	/**
	 * 跳转住院管理界面
	 * @return
	 */
	@RequestMapping("/to_hspt_live_In_manage")
	public String to_hspt_live_In_manage( ){
		return "hspt_live_In_manage";
		
	}
	/**
	 * 跳转住院通知查询界面
	 * @return
	 */
	@RequestMapping("/to_hspt_live_In_notic")
	public String to_hspt_live_In_notic( ){
		return "hspt_live_In_notic";
		
	}
	/**
	 * 跳转主治医生查询界面
	 * @return
	 */
	@RequestMapping("/to_hspt_Doctor_quary")
	public String to_hspt_live_in_doctor( ){
		return "hspt_Doctor_quary";
		
	}
	/**
	 * 跳转探望查询界面
	 * @return
	 */
	@RequestMapping("/to_hspt_visiter_query")
	public String to_hspt_visiter_query( ){
		return "hspt_visiter_query";
		
	}
	/**
	 * 跳转出院通知界面
	 * @return
	 */
	@RequestMapping("/to_hspt_live_out_notic")
	public String to_liveOutNoticPage(){
		return "hspt_live_out_notic";
	}
	/**
	 * 根据姓名查询出院通知
	 * @param likeName
	 * @return
	 */
	@RequestMapping("/to_queryLiveOutNoticByLikeName")
	@ResponseBody
	public List<HospWorkOutNotice> queryLiveOutNoticByLikeName(String likeName){
		return liveOutService.queryLiveOutNoticByLikeName(likeName);
	}
	/**
	 * 住院判断信息
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_returnLiveOutInfo")
	@ResponseBody
	public Map<String,Object> returnLiveOutInfo(String liveID){
		return liveOutService.decideToLiveOut(liveID);
		
	}
	/**
	 * 创建出院号
	 * @return
	 */
	@RequestMapping("/to_returnLiveOutID")
	@ResponseBody
	public String createLiveOutID(){
		return liveOutService.createLiveOutID();
		
	}
	/**
	 * 根据住院号查询床位
	 * @param liveID
	 * @return
	 */
	@RequestMapping("/to_findBedInfoByLiveID")
	@ResponseBody
	public Map<String,Object> findBedInfoByLiveID(String liveID){
		return lv.queryBedIdByLiveID(liveID);
		
	}
	/**
	 * 出院登记
	 * @param liveoutTable
	 * @return
	 */
	@RequestMapping("/to_liveOutNew")
	@ResponseBody
	public boolean newLiveOut(LiveoutTable liveoutTable){
		return liveOutService.liveOut(liveoutTable);
	}
	
	
	

}
